package com.honey.compilation.sql.ddl;

import com.honey.compilation.sql.SqlKeyWord;
import com.honey.compilation.sql.SqlTable;
import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.CompilationException;
import com.honey.core.utils.StringUtility;

/**
 * 修改表命令: ALERT TABLE
 * @author Administrator
 */
abstract class AlterTable extends Alter{
	
	/** 数据库表 */
	private  SqlTable table;
	/**
	 * 构造函数
	 * @param tableName 数据库表名称
	 */
	public AlterTable(String tableName){
		this.table = new SqlTable(tableName);
	}
	
	/**
	 * 构造函数
	 * @param table 数据库表对象
	 */
	public AlterTable(SqlTable table){
		this.table = table;
	}
	
	/**
	 * 构造函数
	 * @param schema 数据库schema 
	 * @param tableName 数据库名称
	 */
	public AlterTable(String schema,String tableName){
		table = new SqlTable(schema,tableName);	
	}
	
	/**
	 * 获取数据库schema
	 * @return
	 */
	public String getSchema() {
		return table.getSchema();
	}
	
	/**
	 * 设定数据库schema
	 * @param schema
	 */
	public void setSchema(String schema) {
		this.table.setSchema(schema);
	}
	
	/**
	 * 获取数据库名称
	 * @return
	 */
	public String getTableName() {
		return this.table.getTableName();
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.core.dom.sql.ddl.Alter#compiledContent(int)
	 */
	@Override
	public CharacterBuilder compiledContent(int indentLevel ) throws CompilationException {
		if( ! StringUtility.stringHasValue(this.getTableName() ) )
			throw new CompilationException("没有tablename");

		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder() 
		.append( super.compiledContent(indentLevel) )
		.append( SqlKeyWord.TABLE )
		.append(table.compiledContent(0));

		return answer;
	}
}
